| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\admin\model\stock;
- use think\Model;
- use fast\Tree;
- class Customer extends Model {
- // 表名
- protected $name = 'stock_customer';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- // 追加属性
- protected $append = [
- 'enabledmark_text'
- ];
- protected static function init() {
- self::afterInsert(function ($row) {
- $pk = $row->getPk();
- $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
- });
- }
- public function getEnabledmarkList() {
- return ['1' => __('Enabledmark 1'), '0' => __('Enabledmark 0')];
- }
- public function getEnabledmarkTextAttr($value, $data) {
- $value = $value ? $value : $data['enabledmark'];
- $list = $this->getEnabledmarkList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- // public function getCustomerTree()
- // {
- // $customerList = collection(model('StockCustomer')->select())->toArray();
- // Tree::instance()->init($customerList);
- // $customer = [];
- // $this->customerList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
- // $primary = array(array('name'=>'==请选择上级==','id'=>''));
- // $result = array_merge_recursive($primary, $this->customerList);
- // foreach ($result as $k => $v) {
- // $customer[$v['id']] = $v['name'];
- // }
- // return $customer;
- // }
- }
|