Customer.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\admin\model\stock;
  3. use think\Model;
  4. use fast\Tree;
  5. class Customer extends Model {
  6. // 表名
  7. protected $name = 'stock_customer';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'enabledmark_text'
  16. ];
  17. protected static function init() {
  18. self::afterInsert(function ($row) {
  19. $pk = $row->getPk();
  20. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  21. });
  22. }
  23. public function getEnabledmarkList() {
  24. return ['1' => __('Enabledmark 1'), '0' => __('Enabledmark 0')];
  25. }
  26. public function getEnabledmarkTextAttr($value, $data) {
  27. $value = $value ? $value : $data['enabledmark'];
  28. $list = $this->getEnabledmarkList();
  29. return isset($list[$value]) ? $list[$value] : '';
  30. }
  31. // public function getCustomerTree()
  32. // {
  33. // $customerList = collection(model('StockCustomer')->select())->toArray();
  34. // Tree::instance()->init($customerList);
  35. // $customer = [];
  36. // $this->customerList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  37. // $primary = array(array('name'=>'==请选择上级==','id'=>''));
  38. // $result = array_merge_recursive($primary, $this->customerList);
  39. // foreach ($result as $k => $v) {
  40. // $customer[$v['id']] = $v['name'];
  41. // }
  42. // return $customer;
  43. // }
  44. }