Consult.php 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //咨询单
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  59. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  60. $role=$this->checkRole();
  61. if(!empty($role['write'])){
  62. $where[]=["b.createrid","in",$role['write']];
  63. }
  64. // if(!empty($role['platform']) ){
  65. // $where[]=["b.platform_code","in",$role['platform']];
  66. // }
  67. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  68. ->count();
  69. $total = ceil($count / $size);
  70. $page = $page >= $total ? $total : $page;
  71. $list = Db::name('consult_info')
  72. ->alias("a")
  73. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  74. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  75. ->where($where)
  76. ->page($page, $size)
  77. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  78. ->order("a.id desc")
  79. ->cursor();
  80. $data=[];
  81. foreach ($list as $value){
  82. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  83. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  84. true):[];
  85. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  86. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  87. $value['khname']="";
  88. if($value['khNo']!==""){
  89. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  90. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  91. }
  92. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  93. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  94. $data[]=$value;
  95. }
  96. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  97. }
  98. public function info(){
  99. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  100. if($id==""){
  101. return error_show(1002,"咨询单编号不能为空");
  102. }
  103. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  104. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  105. $fo['can']=$in;
  106. if(empty($fo)){
  107. return error_show(1002,"未找到咨询单编号");
  108. }else{
  109. return app_show(0,"获取成功",$fo);
  110. }
  111. }
  112. public function del(){
  113. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  114. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  115. if($de==false){
  116. return error_show(1002,'咨询单信息未找到');
  117. }
  118. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  119. if($dell){
  120. return error_show(0,"删除成功");
  121. }else
  122. return error_show(1002,"删除失败");
  123. }
  124. public function create(){
  125. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  126. if($is_project===""){
  127. return error_show(1002,"参数is_project不能为空");
  128. }
  129. if($is_project==1){
  130. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  131. if($projectNo===""){
  132. return error_show(1002,"参数projectNo不能为空");
  133. }
  134. }
  135. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  136. if($khNo===""){
  137. return error_show(1002,"参数khNo不能为空");
  138. }
  139. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  140. if($companyNo===""){
  141. return error_show(1002,"参数companyNo不能为空");
  142. }
  143. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  144. if($endtime===""){
  145. return error_show(1002,"参数endtime不能为空");
  146. }
  147. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  148. "";
  149. if($platform_code===""){
  150. return error_show(1002,"参数platform_code不能为空");
  151. }
  152. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  153. if($ladder==""){
  154. return error_show(1005,"参数ladder不能为空");
  155. }
  156. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  157. if($token==''){
  158. return error_show(105,"参数token不能为空");
  159. }
  160. $user =GetUserInfo($token);
  161. if(empty($user)||$user['code']!=0){
  162. return error_show(102,"用户数据不存在");
  163. }
  164. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  165. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  166. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  167. $zxNo=makeNo("ZX");
  168. Db::startTrans();
  169. try{
  170. $data=[
  171. "zxNo"=>$zxNo,
  172. "createrid"=>$createrid,
  173. "creater"=>$creater,
  174. "is_project"=>$is_project,
  175. "projectNo"=>isset($projectNo) ? $projectNo:"",
  176. "khNo"=>$khNo,
  177. "companyNo"=>$companyNo,
  178. "endtime"=>$endtime,
  179. "salesman"=>$creater,
  180. "platform_code"=>$platform_code,
  181. "saleid"=>$createrid,
  182. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  183. "status"=>0,
  184. "is_del"=>0,
  185. "addtime"=>date("Y-m-d H:i:s"),
  186. "updatetime"=>date("Y-m-d H:i:s"),
  187. ];
  188. $zx = Db::name("consult_order")->insert($data);
  189. if($zx){
  190. foreach ($ladder as $value){
  191. $infoNo=makeNo("IF");
  192. $specinfo=[];
  193. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  194. foreach ($value["specinfo"] as $v){
  195. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  196. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  197. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  198. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  199. $specinfo[]=$v;
  200. }
  201. }
  202. $info=[
  203. "infoNo"=>$infoNo,
  204. "zxNo"=>$zxNo,
  205. "spuCode"=>"",
  206. "good_name"=>$value['good_name'],
  207. "good_img"=>$value['good_img'],
  208. "cat_id"=>$value['cat_id'],
  209. "unit"=>$value['unit'],
  210. "brand_id"=>$value['brand_id'],
  211. "arrival_time"=>$value['arrival_time'],
  212. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  213. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  214. "is_addrs"=>$value['is_addrs'],
  215. "is_custom"=>$value['is_custom'],
  216. "metal_id"=>$value['metal_id'],
  217. "config"=>isset($value['config'])?$value['config']:"",
  218. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  219. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  220. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  221. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  222. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  223. "budget_price"=>$value['budget_price'],
  224. "num"=>$value['num'],
  225. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  226. "use_desc"=>$value['use_desc'],
  227. "remark"=>$value['remark'],
  228. "status"=>1,
  229. "is_del"=>0,
  230. "addtime"=>date("Y-m-d H:i:s"),
  231. "updatetime"=>date("Y-m-d H:i:s"),
  232. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  233. ];
  234. $up = Db::name("consult_info")->insert($info);
  235. if(!$up){
  236. Db::rollback();
  237. return error_show(1004,'添加失败');
  238. }else{
  239. //修改状态,添加待办
  240. ActionLog::logAdd($this->post['token'], [
  241. "order_code" => $infoNo,//咨询单详情编号
  242. "status" => 1,//这里的status是之前的值
  243. "action_remark" => '',//备注
  244. "action_type" => "create"//新建create,编辑edit,更改状态status
  245. ], "ZXD", 1, $info);
  246. // ProcessOrder::AddProcess($this->post['token'], [
  247. // "order_type" => 'ZXD',
  248. // "order_code" => $infoNo,//咨询单详情编号
  249. // "order_id" => 0,
  250. // "order_status" => 1
  251. // ]);
  252. }
  253. }
  254. Db::commit();
  255. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  256. }else{
  257. Db::rollback();
  258. return error_show(1004,"新建失败");
  259. }
  260. }catch (\Exception $e){
  261. Db::rollback();
  262. return error_show(1003,$e->getMessage());
  263. }
  264. }
  265. public function zxinfo(){
  266. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  267. if($infoNo==""){
  268. return error_show(1004,"参数infoNo不能为空");
  269. }
  270. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  271. if($zxinfo==false){
  272. return error_show(1004,"未找到信息数据");
  273. }
  274. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  275. if($zxorder==false){
  276. return error_show(1004,"未找到咨询信息数据");
  277. }
  278. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  279. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  280. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  281. $zxinfo['khname']="";
  282. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  283. $zxinfo['khNo']="";
  284. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  285. $zxinfo['brand']="";
  286. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  287. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  288. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  289. $zxinfo['company']="";
  290. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  291. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  292. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  293. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  294. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  295. $zxinfo['project_name']="";
  296. $zxinfo['budget_total']="";
  297. $zxinfo['departinfo']=[];
  298. $zxinfo['unit_name']="";
  299. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  300. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  301. if($zxorder['khNo']!==""){
  302. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  303. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  304. $zxinfo['khNo']= $zxorder['khNo'];
  305. }
  306. if($zxinfo['unit']!==""){
  307. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  308. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  309. }
  310. if($zxinfo['brand_id']!==""){
  311. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  312. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  313. }
  314. if($zxorder['companyNo']!==""){
  315. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  316. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  317. }
  318. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  319. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  320. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  321. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  322. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  323. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  324. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  325. }
  326. if($zxorder['depart']>0){
  327. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  328. }
  329. if($zxorder['platform_code']>0){
  330. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  331. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  332. }
  333. return app_show(0,"获取成功",$zxinfo);
  334. }
  335. public function zxedit(){
  336. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  337. if($infoNo==""){
  338. return error_show(1004,"参数infoNo不能为空");
  339. }
  340. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  341. if($zxinfo==false){
  342. return error_show(1004,"未找到信息数据");
  343. }
  344. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  345. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  346. if($good_name==""){
  347. return error_show(1003,"参数good_name不能为空");
  348. }
  349. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  350. if($good_img==""){
  351. return error_show(1003,"参数good_img不能为空");
  352. }
  353. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  354. if($cat_id==""){
  355. return error_show(1003,"参数cat_id不能为空");
  356. }
  357. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  358. if($unit==""){
  359. return error_show(1003,"参数unit不能为空");
  360. }
  361. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  362. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  363. if($arrival_time==""){
  364. return error_show(1003,"参数arrival_time不能为空");
  365. }
  366. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  367. if($specin==""){
  368. return error_show(1003,"参数specinfo不能为空");
  369. }
  370. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  371. // if($cost_desc==""){
  372. // return error_show(1003,"参数cost_desc不能为空");
  373. // }
  374. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  375. if($is_addrs===""){
  376. return error_show(1003,"参数is_addrs不能为空");
  377. }
  378. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  379. if($is_custom===""){
  380. return error_show(1003,"参数is_custom不能为空");
  381. }
  382. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  383. if($metal_id===""){
  384. return error_show(1003,"参数metal_id不能为空");
  385. }
  386. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  387. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  388. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  389. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  390. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  391. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  392. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  393. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  394. if($num===""){
  395. return error_show(1003,"参数num不能为空");
  396. }
  397. if($budget_price===""){
  398. return error_show(1003,"参数budget_price不能为空");
  399. }
  400. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  401. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  402. if($use_desc==""){
  403. return error_show(1003,"参数use_desc不能为空");
  404. }
  405. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  406. if($remark==""){
  407. return error_show(1003,"参数remark不能为空");
  408. }
  409. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  410. if($endtime==""){
  411. return error_show(1003,"参数endtime不能为空");
  412. }
  413. if($metal_id!=0){
  414. if($config==""){
  415. return error_show(1003,"参数config不能为空");
  416. }
  417. if($other_config==""){
  418. return error_show(1003,"参数other_config不能为空");
  419. }
  420. if($specs_weight===""){
  421. return error_show(1003,"参数specs_weight不能为空");
  422. }
  423. if($gold_price===""){
  424. return error_show(1003,"参数gold_price不能为空");
  425. }
  426. }
  427. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  428. if($token==''){
  429. return error_show(102,"参数token不能为空");
  430. }
  431. $user =GetUserInfo($token);
  432. if(empty($user)||$user['code']!=0){
  433. return error_show(105,"用户数据不存在");
  434. }
  435. $specinfo=[];
  436. foreach ($specin as $v){
  437. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  438. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  439. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  440. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  441. $specinfo[]=$v;
  442. }
  443. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  444. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  445. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  446. Db::startTrans();
  447. try{
  448. $innew =makeNo("IF");
  449. $info=[
  450. "infoNo"=>$innew,
  451. "zxNo"=>$zxinfo['zxNo'],
  452. "spuCode"=>"",
  453. "good_name"=>$good_name,
  454. "good_img"=>$good_img,
  455. "cat_id"=>$cat_id,
  456. "unit"=>$unit,
  457. "brand_id"=>$brand_id,
  458. "arrival_time"=>$arrival_time,
  459. "specinfo"=>json_encode($specinfo),
  460. // "color"=>$color,
  461. // "material"=>$material,
  462. "cost_desc"=>$cost_desc,
  463. "is_addrs"=>$is_addrs,
  464. "is_custom"=>$is_custom,
  465. "metal_id"=>$metal_id,
  466. "config"=>$config,
  467. "other_config"=>$other_config,
  468. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  469. "gold_price"=>$gold_price===""? 0 : $gold_price,
  470. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  471. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  472. "budget_price"=>$budget_price,
  473. "num"=>$num,
  474. "pgNo"=>$pgNo,
  475. "use_desc"=>$use_desc,
  476. "remark"=>$remark,
  477. "status"=>1,
  478. "is_del"=>0,
  479. "addtime"=>date("Y-m-d H:i:s"),
  480. "updatetime"=>date("Y-m-d H:i:s"),
  481. 'bargain_status'=>1,
  482. 'enclosure_file'=>$enclosure_file
  483. ];
  484. $up = Db::name("consult_info")->insert($info);
  485. if($up){
  486. //操作记录
  487. ActionLog::logAdd($this->post['token'], [
  488. "order_code" => $innew,//咨询单详情编号
  489. "status" => 1,//这里的status是之前的值
  490. "action_remark" => '',//备注
  491. "action_type" => "edit"//新建create,编辑edit,更改状态status
  492. ], "ZXD", 1, $this->post);
  493. // ProcessOrder::AddProcess($this->post['token'], [
  494. // "order_type" => 'ZXD',
  495. // "order_code" => $innew,//咨询单详情编号
  496. // "order_id" => 0,
  497. // "order_status" => 1
  498. // ]);
  499. if (!empty($bidlist)){
  500. foreach ($bidlist as $value){
  501. unset($value['id']);
  502. $value['infoNo']=$innew;
  503. $value['bidNo']=makeNo("BD");
  504. $value['spuCode']=makeNo("SKU");
  505. $value['status'] =0;
  506. $value['updatetime'] =date("Y-m-d H:i:s");
  507. $in = Db::name("consult_bids")->insert($value);
  508. if($in==false){
  509. Db::rollback();
  510. return error_show(1004,"反馈商品新建失败");
  511. }
  512. ActionLog::logAdd($this->post['token'], [
  513. "order_code" => $innew,//咨询单详情编号
  514. "status" => 1,//这里的status是之前的值
  515. "action_remark" => '',//备注
  516. "action_type" => "edit"//新建create,编辑edit,更改状态status
  517. ], "FKD", 1, $this->post);
  518. }
  519. }
  520. $zxinfo["bargain_status"] =1;
  521. $zxinfo["bargain_code"] =$innew;
  522. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  523. $bar=Db::name("consult_info")->save($zxinfo);
  524. if($bar==false){
  525. Db::rollback();
  526. return error_show(1004,"反馈商品更新失败");
  527. }else{
  528. //修改状态,添加待办
  529. ActionLog::logAdd($this->post['token'], [
  530. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  531. "status" => $zxinfo['status'],//这里的status是之前的值
  532. "action_remark" => '',//备注
  533. "action_type" => "edit"//新建create,编辑edit,更改状态status
  534. ], "ZXD", $zxinfo['status'], $zxinfo);
  535. }
  536. //更新consule_order记录
  537. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  538. 'updatetime'=>date('Y-m-d H:i:s')]);
  539. if($op==false){
  540. Db::rollback();
  541. return error_show(1004,'咨询单结束时间更新失败');
  542. }
  543. Db::commit();
  544. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  545. }
  546. }catch (\Exception $e){
  547. Db::rollback();
  548. return error_show(1004,$e->getMessage());
  549. }
  550. }
  551. //** 发布竞标任务 */
  552. public function bargain(){
  553. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  554. if($infoNo==""){
  555. return error_show(1004,"参数infoNo不能为空");
  556. }
  557. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  558. if($zxinfo==false){
  559. return error_show(1004,"未找到信息数据");
  560. }
  561. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  562. if($status===""){
  563. return error_show(1004,"参数status不能为空");
  564. }
  565. // if($status==1&&$zxinfo['status']>1){
  566. // $zxinfo['bargain_num']=+1;
  567. // }
  568. $old_zxinfo_status = $zxinfo['status'];
  569. $zxinfo['status']=$status;
  570. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  571. $up = Db::name("consult_info")->save($zxinfo);
  572. if($up){
  573. //修改状态,添加待办
  574. ActionLog::logAdd($this->post['token'], [
  575. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  576. "status" => $old_zxinfo_status,//这里的status是之前的值
  577. "action_remark" => '',//备注
  578. "action_type" => "status"//新建create,编辑edit,更改状态status
  579. ], "ZXD", $zxinfo['status'], $zxinfo);
  580. return app_show(0,"状态更新成功");
  581. }else{
  582. return error_show(1003,"状态更新失败");
  583. }
  584. }
  585. //反馈商品添加
  586. public function feadback(){
  587. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  588. if($infoNo==""){
  589. return error_show(1002,"参数infoNo不能为空");
  590. }
  591. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  592. if($zxinfo==false){
  593. return error_show(1003,"未找到信息数据");
  594. }
  595. if($zxinfo['status']!=1){
  596. return error_show(1004,"任务未进行");
  597. }
  598. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  599. if($zx==false){
  600. return error_show(1003,"未找咨询信息数据");
  601. }
  602. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  603. if($pname==""){
  604. return error_show(1002,"参数pname不能为空");
  605. }
  606. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  607. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  608. if($cat_id==""){
  609. return error_show(1002,"参数cat_id不能为空");
  610. }
  611. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  612. if($specin==""){
  613. return error_show(1003,"参数specinfo不能为空");
  614. }
  615. $specinfo=[];
  616. foreach ($specin as $v){
  617. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  618. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  619. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  620. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  621. $specinfo[]=$v;
  622. }
  623. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  624. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  625. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  626. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  627. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  628. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  629. :"";
  630. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  631. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  632. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  633. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  634. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  635. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  636. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  637. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  638. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  639. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  640. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  641. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  642. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  643. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  644. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  645. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  646. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  647. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  648. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  649. if($nake_fee==="" ){
  650. return error_show(1004,"参数nake_fee不能为空");
  651. }
  652. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  653. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  654. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  655. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  656. if($delivery_place==''){
  657. return error_show(1002,"参数delivery_place不能为空");
  658. }
  659. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  660. if($token==''){
  661. return error_show(1002,"参数token不能为空");
  662. }
  663. $user =GetUserInfo($token);
  664. if(empty($user)||$user['code']!=0){
  665. return error_show(1005,"用户数据不存在");
  666. }
  667. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  668. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  669. $bidNo=makeNo("BD");
  670. $spucode=makeNo("SKU");
  671. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  672. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  673. //部分参数的大小校验
  674. $vali = Validate::rule([
  675. 'expire_day|有效时长'=>'require|elt:214748364',
  676. 'delivery_day|物流时长'=>'require|elt:214748364',
  677. 'work_day|生产工期'=>'require|elt:214748364',
  678. 'weight|总重量'=>'require|max:10',
  679. ]);
  680. $temp = [
  681. 'expire_day'=>$expire_day,
  682. 'delivery_day'=>$delivery_day,
  683. 'work_day'=>$work_day,
  684. 'weight'=>$weight,
  685. ];
  686. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  687. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  688. $cat_top_list = made($cat_id);
  689. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  690. if ($is_gold_price == 1 && $cat_top_id == 6) {
  691. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  692. ->find();
  693. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  694. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  695. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  696. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  697. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  698. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  699. $saleprice = $total_fee/ (1 - $budget);
  700. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  701. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  702. }else{
  703. if($nake_fee){
  704. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  705. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  706. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  707. }else{
  708. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  709. (1 - $budget);
  710. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  711. }
  712. }
  713. $data=[
  714. "bidNo"=>$bidNo,
  715. "infoNo"=>$infoNo,
  716. "zxNo"=>$zxinfo['zxNo'],
  717. "spuCode"=>$spucode,
  718. "good_name"=>$pname,
  719. "brand_id"=>$brandid,
  720. "cat_id"=>$cat_id,
  721. "specinfo"=>json_encode($specinfo),
  722. "unit_id"=>$unit_id,
  723. "cost_desc"=>$cost_desc,
  724. "work_day"=>$work_day,
  725. "delivery_day"=>$delivery_day,
  726. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  727. "expire_day"=>$expire_day,
  728. "origin_place"=>$origin_place,
  729. "supplierNo"=>$supplierNo,
  730. "pay_way"=>$pay_way,
  731. "tax"=>$tax,
  732. "send_way"=>$send_way,
  733. "metal_id"=>$metal_id,
  734. "is_gold_price"=>$is_gold_price,
  735. "config"=>$config,
  736. "other_config"=>$other_config,
  737. "weight"=>$weight,
  738. "good_weight"=>$good_weight,
  739. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  740. "is_diff"=>$is_diff,
  741. "demo_fee"=>$demo_fee,
  742. "delivery_fee"=>$delivery_fee,
  743. "open_fee"=>$open_fee,
  744. "pakge_fee"=>$pakge_fee,
  745. "nake_fee"=>$nake_fee,
  746. "mark_fee"=>$mark_fee,
  747. "cert_fee"=>$cert_fee,
  748. "cost_fee"=>$cost_fee,
  749. "total_fee"=>$total_fee,
  750. "supply_area"=>$supply_area,
  751. "remark"=>$remark,
  752. "sale_price"=>$saleprice,
  753. "sale_cost_fee"=>$sale_cost_fee,
  754. "origin_cost_fee"=>$sale_cost_fee,
  755. "origin_price"=>$saleprice,
  756. "createrid"=>$createrid,
  757. "creater"=>$creater,
  758. "status"=>$zxinfo['status']==1 ?1 :2,
  759. "is_del"=>0,
  760. "addtime"=>date("Y-m-d H:i:s"),
  761. "updatetime"=>date("Y-m-d H:i:s"),
  762. 'delivery_place'=>$delivery_place//发货地
  763. ];
  764. Db::startTrans();
  765. try{
  766. $insert= Db::name("consult_bids")->insert($data);
  767. if($insert){
  768. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  769. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  770. if($projectinfo==false){
  771. Db::rollback();
  772. return error_show(1006,"未找到项目信息");
  773. }
  774. $temp=[];
  775. $temp['spuCode']=$spucode;
  776. $temp['skuCode']="";
  777. $temp['pgNo']=$zxinfo['pgNo'];
  778. $temp['projectNo']=$zx['projectNo'];
  779. $temp['good_name']=$pname;
  780. $temp['good_type']=$projectinfo['good_type'];
  781. $temp['data_source']=2;
  782. $temp['cat_id']=$cat_id;
  783. $temp['budget_price']=$projectinfo['budget_price'];
  784. $temp['sale_price']=$saleprice;
  785. $temp['origin_price']=$total_fee;
  786. $temp['num']=$zxinfo['num'];
  787. $temp['status']=0;
  788. $temp['is_del']=0;
  789. $temp['creater']=$creater;
  790. $temp['createrid']=$createrid;
  791. $temp['addtime']=date("Y-m-d H:i:s");
  792. $temp['updatetime']=date("Y-m-d H:i:s");
  793. $nu = Db::name("project_feedback")->insert($temp);
  794. if($nu==false){
  795. Db::rollback();
  796. return error_show(1006,"项目反馈失败");
  797. }else{
  798. $old_projectinfo_status = $projectinfo['status'];
  799. $projectinfo['status']=2;
  800. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  801. $up = Db::name("project_info")->save($projectinfo);
  802. if($up){
  803. //修改状态,添加待办,只记录动作
  804. ActionLog::logAdd($this->post['token'], [
  805. "order_code" => $projectinfo['pgNo'],//编码
  806. "status" => $old_projectinfo_status,//这里的status是之前的值
  807. "action_remark" => '',//备注
  808. "action_type" => "status"//新建create,编辑edit,更改状态status
  809. ], "PRI", 2, $projectinfo);
  810. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  811. ->count();
  812. if($count==0){
  813. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  814. if($projetc!=false){
  815. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  816. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  817. if($proc==false){
  818. Db::rollback();
  819. return error_show(1006,"项目反馈失败");
  820. }else{
  821. //修改状态,添加待办
  822. ActionLog::logAdd($this->post['token'], [
  823. "order_code" => $projetc['projectNo'],//项目编码
  824. "status" => 1,//这里的status是之前的值
  825. "action_remark" => '',//备注
  826. "action_type" => "status"//新建create,编辑edit,更改状态status
  827. ], "PRO", 2, $projetc);
  828. ProcessOrder::AddProcess($this->post['token'], [
  829. "order_type" => 'PRO',
  830. "order_code" => $projetc['projectNo'],
  831. "order_id" => $projetc['id'],
  832. "order_status" => 2,"before_status"=>1
  833. ]);
  834. }
  835. }
  836. }
  837. }
  838. }
  839. }
  840. Db::commit();
  841. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  842. }else{
  843. Db::rollback();
  844. return error_show(1006,"反馈失败");
  845. }
  846. }catch (\Exception $e){
  847. Db::rollback();
  848. return error_show(1006,$e->getMessage());
  849. }
  850. }
  851. //反馈商品详情
  852. public function feadinfo(){
  853. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  854. if($bidNo==""){
  855. return error_show(1004,"参数bidNo不能为空");
  856. }
  857. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  858. if($info==false){
  859. return error_show(1004,"未找到商品数据");
  860. }
  861. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  862. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  863. $info['cat_info'] = made($info['cat_id'],[]);
  864. $info['noble_weight'] = $info['good_weight'];
  865. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  866. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  867. if($info['brand_id']!=0){
  868. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  869. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  870. }else{
  871. $info["brand_name"]="";
  872. $info["brand_id"]="";
  873. }
  874. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  875. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  876. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  877. $god=[
  878. "metal_id"=>$info['metal_id'],
  879. "weight"=>$info["good_weight"],
  880. "demo_fee"=>$info["demo_fee"],
  881. "delivery_fee"=>$info["delivery_fee"],
  882. "open_fee"=>$info["open_fee"],
  883. "packing_fee"=>$info["pakge_fee"],
  884. "mark_fee"=>$info["mark_fee"],
  885. "nake_fee"=>$info["nake_fee"],
  886. "cert_fee"=>$info["cert_fee"],
  887. "cost_fee"=>$info["cost_fee"],
  888. "num"=>$bidinfo["num"],
  889. ];
  890. if($info['is_gold_price']==1){
  891. $price = GoldPrice($god, $budget/100);
  892. $info['sale_price'] =round($price,2);
  893. }
  894. $info['specinfo'] = json_decode($info['specinfo'],true);
  895. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  896. if($info['delivery_place']!=""){
  897. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  898. }
  899. $info['delivery_place_cn']=GetAddr(json_encode($place));
  900. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  901. if($info['origin_place']!=""){
  902. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  903. }
  904. $info['origin_place_cn']=GetAddr(json_encode($place));
  905. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  906. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  907. $info['bargain'] =$bargain;
  908. $info['good_img'] = explode(',',$info['good_img']);
  909. return app_show(0,"获取成功",$info);
  910. }
  911. //反馈商品编辑
  912. public function feededit(){
  913. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  914. if($bidNo==""){
  915. return error_show(1002,"参数bidNo不能为空");
  916. }
  917. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  918. if($bidinfo==false){
  919. return error_show(1003,"未找到信息数据");
  920. }
  921. if($bidinfo['status']>=5){
  922. return error_show(1004,"咨询单已确认无法修改");
  923. }
  924. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  925. if($zxinfo==false){
  926. return error_show(1003,"未找到信息数据");
  927. }
  928. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  929. if($zx==false){
  930. return error_show(1003,"未找咨询信息数据");
  931. }
  932. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  933. if($pname==""){
  934. return error_show(1002,"参数pname不能为空");
  935. }
  936. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  937. // if($brandid==""){
  938. // return error_show(1002,"参数brandid不能为空");
  939. // }
  940. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  941. if($cat_id==""){
  942. return error_show(1002,"参数cat_id不能为空");
  943. }
  944. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  945. if($specin==""){
  946. return error_show(1003,"参数specinfo不能为空");
  947. }
  948. $specinfo=[];
  949. foreach ($specin as $v){
  950. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  951. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  952. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  953. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  954. $specinfo[]=$v;
  955. }
  956. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  957. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  958. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  959. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  960. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  961. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  962. :"";
  963. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  964. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  965. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  966. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  967. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  968. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  969. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  970. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  971. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  972. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  973. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  974. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  975. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  976. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  977. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  978. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  979. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  980. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  981. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  982. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  983. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  984. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  985. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  986. if($delivery_place==''){
  987. return error_show(1002,"参数delivery_place不能为空");
  988. }
  989. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  990. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  991. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  992. $cat_top_list = made($cat_id);
  993. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  994. if ($is_gold_price == 1 && $cat_top_id == 6) {
  995. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  996. ->find();
  997. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  998. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  999. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1000. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1001. $saleprice = $total_fee / (1 - $budget);
  1002. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1003. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1004. }else{
  1005. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1006. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1007. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1008. }
  1009. Db::startTrans();
  1010. try{
  1011. $data=[
  1012. "good_name"=>$pname,
  1013. "brand_id"=>$brandid,
  1014. "cat_id"=>$cat_id,
  1015. "specinfo"=>json_encode($specinfo),
  1016. // "material"=>$material,
  1017. "unit_id"=>$unit_id,
  1018. "cost_desc"=>$cost_desc,
  1019. "work_day"=>$work_day,
  1020. "delivery_day"=>$delivery_day,
  1021. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1022. "expire_day"=>$expire_day,
  1023. "origin_place"=>$origin_place,
  1024. "supplierNo"=>$supplierNo,
  1025. "pay_way"=>$pay_way,
  1026. "tax"=>$tax,
  1027. "send_way"=>$send_way,
  1028. "metal_id"=>$metal_id,
  1029. "is_gold_price"=>$is_gold_price,
  1030. "config"=>$config,
  1031. "other_config"=>$other_config,
  1032. "weight"=>$weight,
  1033. "good_weight"=>$noble_weight,
  1034. "is_diff"=>$is_diff,
  1035. "demo_fee"=>$demo_fee,
  1036. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1037. "delivery_fee"=>$delivery_fee,
  1038. "open_fee"=>$open_fee,
  1039. "pakge_fee"=>$pakge_fee,
  1040. "nake_fee"=>$nake_fee,
  1041. "mark_fee"=>$mark_fee,
  1042. "cert_fee"=>$cert_fee,
  1043. "cost_fee"=>$cost_fee,
  1044. "sale_cost_fee"=>$sale_cost_fee,
  1045. "origin_cost_fee"=>$sale_cost_fee,
  1046. "total_fee"=>$total_fee,
  1047. "sale_price"=>$saleprice,
  1048. "origin_price"=>$saleprice,
  1049. "supply_area"=>$supply_area,
  1050. "remark"=>$remark,
  1051. "status"=>0,
  1052. "updatetime"=>date("Y-m-d H:i:s"),
  1053. 'delivery_place' => $delivery_place
  1054. ];
  1055. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1056. if($insert){
  1057. if($zxinfo['bargain_status']==1){
  1058. $zxinfo['bargain_status']=0;
  1059. $infoip =Db::name("consult_info")->save($zxinfo);
  1060. if($infoip==false){
  1061. Db::rollback();
  1062. return error_show(1006,"咨询信息状态更新失败");
  1063. }
  1064. }
  1065. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1066. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1067. if($projectinfo==false){
  1068. Db::rollback();
  1069. return error_show(1006,"未找到项目信息");
  1070. }
  1071. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1072. if($feed==false){
  1073. Db::rollback();
  1074. return error_show(1006,"未找到项目反馈信息");
  1075. }
  1076. $feed['good_name']=$pname;
  1077. $feed['good_type']=$projectinfo['good_type'];
  1078. $feed['cat_id']=$cat_id;
  1079. $feed['sale_price']=$saleprice;
  1080. $feed['origin_price']=$total_fee;
  1081. $feed['updatetime']=date("Y-m-d H:i:s");
  1082. $temp['updatetime']=date("Y-m-d H:i:s");
  1083. $nu = Db::name("project_feedback")->save($feed);
  1084. if($nu==false){
  1085. Db::rollback();
  1086. return error_show(1006,"项目反馈失败");
  1087. }else{
  1088. $old_projectinfo_status = $projectinfo['status'];
  1089. $projectinfo['status']=2;
  1090. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1091. $up = Db::name("project_info")->save($projectinfo);
  1092. if($up){
  1093. //修改状态,添加待办,只记录动作
  1094. ActionLog::logAdd($this->post['token'], [
  1095. "order_code" => $projectinfo['pgNo'],//编码
  1096. "status" => $old_projectinfo_status,//这里的status是之前的值
  1097. "action_remark" => '',//备注
  1098. "action_type" => "status"//新建create,编辑edit,更改状态status
  1099. ], "PRI", 2, $projectinfo);
  1100. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1101. if ($count == 0) {
  1102. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1103. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1104. if ($project_id) {
  1105. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1106. if ($proc == false) {
  1107. Db::rollback();
  1108. return error_show(1006, "项目反馈失败");
  1109. }else{
  1110. //修改状态,添加待办
  1111. ActionLog::logAdd($this->post['token'], [
  1112. "order_code" => $projectinfo['projectNo'],//项目编码
  1113. "status" => 1,//这里的status是之前的值
  1114. "action_remark" => '',//备注
  1115. "action_type" => "status"//新建create,编辑edit,更改状态status
  1116. ], "PRO", 2, $this->post);
  1117. ProcessOrder::AddProcess($this->post['token'], [
  1118. "order_type" => 'PRO',
  1119. "order_code" => $projectinfo['projectNo'],
  1120. "order_id" => $project_id,
  1121. "order_status" => 2,"before_status"=>1
  1122. ]);
  1123. }
  1124. }
  1125. }
  1126. }
  1127. }
  1128. }
  1129. Db::commit();
  1130. return app_show(0,"编辑成功");
  1131. }else{
  1132. Db::rollback();
  1133. return error_show(1004,"编辑失败");
  1134. }
  1135. }catch (\Exception $e){
  1136. Db::rollback();
  1137. return error_show(1004,$e->getMessage());
  1138. }
  1139. }
  1140. public function bargain_add(){
  1141. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1142. if($bidNo===""){
  1143. return error_show(1004,"参数bidNo不能为空");
  1144. }
  1145. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1146. if($info==false){
  1147. return error_show(1004,"未找到商品数据");
  1148. }
  1149. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1150. if($consult==false){
  1151. return error_show(1004,"未找到咨询数据");
  1152. }
  1153. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1154. if($bargain_price===""){
  1155. return error_show(1004,"参数bargain_price不能为空");
  1156. }
  1157. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1158. if($info['is_gold_price']==1){
  1159. if($cost_price==""){
  1160. return error_show(1004,"参数cost_price不能为空");
  1161. }
  1162. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1163. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1164. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1165. ->find();
  1166. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1167. }
  1168. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1169. // if($bargain_reason===""){
  1170. // return error_show(1004,"参数bargain_reason不能为空");
  1171. // }
  1172. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1173. if($infos==false){
  1174. return error_show(1004,"未找到商品数据");
  1175. }
  1176. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1177. return error_show(1004,"咨询单招标未结束或已确认商品");
  1178. }
  1179. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1180. if($token==''){
  1181. return error_show(105,"参数token不能为空");
  1182. }
  1183. $user =GetUserInfo($token);
  1184. if(empty($user)||$user['code']!=0){
  1185. return error_show(1002,"用户数据不存在");
  1186. }
  1187. //新增两个字段
  1188. //议价备注
  1189. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1190. //议价原因id
  1191. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1192. if ($result_info_id != '') {
  1193. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1194. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1195. }
  1196. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1197. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1198. $bargainNo =makeNo("BA");
  1199. Db::startTrans();//::todo 金价 毛利计算
  1200. try{
  1201. $data=[
  1202. "bidsNo"=>$bidNo,
  1203. "infoNo"=>$info['infoNo'],
  1204. "zxNo"=>$info['zxNo'],
  1205. "bargainNo"=>$bargainNo,
  1206. "bargain_type"=>1,
  1207. "bargain_reason"=>$bargain_reason,
  1208. "sale_price"=>$info['sale_price'],
  1209. "cost_before_price"=>$info['sale_cost_fee'],
  1210. "cost_after_price"=>$cost_price,
  1211. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1212. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1213. "after_price"=>$bargain_price,
  1214. "exam_info"=>"",
  1215. "status"=>0,
  1216. "is_del"=>0,
  1217. "creater"=>$creater,
  1218. "createrid"=>$createrid,
  1219. "addtime"=>date("Y-m-d H:i:s"),
  1220. "updatetime"=>date("Y-m-d H:i:s"),
  1221. 'bargain_remark'=>$bargain_remark,
  1222. 'result_info_id'=>$result_info_id,
  1223. ];
  1224. $int = Db::name("bargain_order")->insert($data);
  1225. if($int){
  1226. //修改状态,添加待办
  1227. ActionLog::logAdd($this->post['token'], [
  1228. "order_code" => $bargainNo,//咨询单详情编号
  1229. "status" => 0,//这里的status是之前的值
  1230. "action_remark" => '',//备注
  1231. "action_type" => "status"//新建create,编辑edit,更改状态status
  1232. ], "YJD", $data['status'], $data);
  1233. ProcessOrder::AddProcess($this->post['token'], [
  1234. "order_type" => 'YJD',
  1235. "order_code" => $bargainNo,
  1236. "order_id" =>Db::name("bargain_order")->getLastInsID(),
  1237. "order_status" =>0,"before_status"=>0
  1238. ]);
  1239. $odlstatus=$info['status'];
  1240. $info['status']=3;
  1241. $info['updatetime']=date("Y-m-d H:i:s");
  1242. $up =Db::name("consult_bids")->save($info);
  1243. if($up){
  1244. //修改状态,添加待办
  1245. ActionLog::logAdd($this->post['token'], [
  1246. "order_code" => $bidNo,//咨询单详情编号
  1247. "status" => $odlstatus,//这里的status是之前的值
  1248. "action_remark" => '',//备注
  1249. "action_type" => "status"//新建create,编辑edit,更改状态status
  1250. ], "FKD", $info['status'], $info);
  1251. $old_infos_status = $infos['status'];
  1252. $infos['status']=3;
  1253. $infos['updatetime']=date("Y-m-d H:i:s");
  1254. $ups =Db::name("consult_info")->save($infos);
  1255. if($ups){
  1256. //修改状态,添加待办
  1257. ActionLog::logAdd($this->post['token'], [
  1258. "order_code" => $infos['infoNo'],//咨询单详情编号
  1259. "status" => $old_infos_status,//这里的status是之前的值
  1260. "action_remark" => '',//备注
  1261. "action_type" => "status"//新建create,编辑edit,更改状态status
  1262. ], "ZXD", $infos['status'], $infos);
  1263. Db::commit();
  1264. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1265. }
  1266. }
  1267. }
  1268. Db::rollback();
  1269. return error_show(1004,"议价单新建失败");
  1270. }catch (\Exception $e){
  1271. Db::rollback();
  1272. return error_show(1004,$e->getMessage());
  1273. }
  1274. }
  1275. //选择商品
  1276. public function bids_check(){
  1277. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1278. if($bidNo===""){
  1279. return error_show(1004,"参数bidNo不能为空");
  1280. }
  1281. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1282. if($info==false){
  1283. return error_show(1004,"未找到商品数据");
  1284. }
  1285. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1286. if($infos==false){
  1287. return error_show(1004,"未找到商品数据");
  1288. }
  1289. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1290. return error_show(1004,"咨询单招标未结束或已确认商品");
  1291. }
  1292. Db::startTrans();
  1293. try {
  1294. $oldstattus=$info['status'];
  1295. $info['status']=6;
  1296. $info['updatetime']=date("Y-m-d H:i:s");
  1297. $bids = Db::name("consult_bids")->save($info);
  1298. if($bids){
  1299. //修改状态,添加待办
  1300. ActionLog::logAdd($this->post['token'], [
  1301. "order_code" =>$bidNo,//咨询单详情编号
  1302. "status" => $oldstattus,//这里的status是之前的值
  1303. "action_remark" => '',//备注
  1304. "action_type" => "status"//新建create,编辑edit,更改状态status
  1305. ], "FKD", $info['status'], $info);
  1306. $old_infos_status = $infos['status'];
  1307. $infos['status']=4;
  1308. $infos['updatetime']=date("Y-m-d H:i:s");
  1309. $se = Db::name("consult_info")->save($infos);
  1310. if($se){
  1311. //修改状态,添加待办
  1312. ActionLog::logAdd($this->post['token'], [
  1313. "order_code" => $infos['infoNo'],//咨询单详情编号
  1314. "status" => $old_infos_status,//这里的status是之前的值
  1315. "action_remark" => '',//备注
  1316. "action_type" => "status"//新建create,编辑edit,更改状态status
  1317. ], "ZXD", $infos['status'], $infos);
  1318. Db::commit();
  1319. return app_show(0,"商品确定成功");
  1320. }
  1321. }
  1322. Db::rollback();
  1323. return error_show(1004,"商品确认失败");
  1324. }catch (\Exception $e){
  1325. Db::rollback();
  1326. return error_show(1004,$e->getMessage());
  1327. }
  1328. }
  1329. //议价审核
  1330. /**
  1331. * status:
  1332. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1333. */
  1334. public function bargain_status(){
  1335. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1336. if($bargainNo===""){
  1337. return error_show(1004,"参数bargainNo不能为空");
  1338. }
  1339. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1340. if($info==false){
  1341. return error_show(1004,"未找到议价数据");
  1342. }
  1343. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1344. if($bids==false){
  1345. return error_show(1004,"未找到商品数据");
  1346. }
  1347. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1348. if($coninfo==false){
  1349. return error_show(1004,"未找到咨询单数据");
  1350. }
  1351. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1352. if($status===''){
  1353. return error_show(1005,"参数status不能为空");
  1354. }
  1355. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1356. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1357. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1358. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1359. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1360. if($bids['is_gold_price']==1){
  1361. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1362. ->find();
  1363. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1364. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1365. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1366. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1367. $saleprice =$total_fe / (1 - $budget);
  1368. $rate_price = $total_fe / (1 - $rate);
  1369. $money_price =$total_fe / (1 - $money_rate);
  1370. $lower_price =$total_fe / (1 - $lower_rate);
  1371. }else{
  1372. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1373. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1374. if($bids['nake_fee']!=0){
  1375. $saleprice = ($total_fe)/ (1 - $budget);
  1376. $rate_price = ($total_fe)/ (1 - $rate);
  1377. $money_price =($total_fe)/ (1 - $money_rate);
  1378. $lower_price = ($total_fe) / (1 - $lower_rate);
  1379. }else{
  1380. $saleprice = $total_fe / (1 - $budget);
  1381. $rate_price =$total_fe/ (1 - $rate);
  1382. $money_price =$total_fe / (1 - $money_rate);
  1383. $lower_price = $total_fe/ (1 - $lower_rate);
  1384. }
  1385. }
  1386. $ra_status = $info['status'];
  1387. if($status==1){
  1388. if($info['status']==0){
  1389. if($info['after_price']<$rate_price){
  1390. $info['status']=2;
  1391. }else{
  1392. $info['status']=1;
  1393. }
  1394. }elseif($info['status']==2){
  1395. $info['status']=4;
  1396. }elseif($info['status']==4||$info['status']==5){
  1397. if($info['after_price']<$money_price){
  1398. $info['status']=7;
  1399. }else{
  1400. $info['status']=6;
  1401. }
  1402. }elseif($info['status']==7){
  1403. $info['lower_price'] =$lower_price;
  1404. if($info['after_price']<$lower_price){
  1405. $info['status']=10;
  1406. }else{
  1407. $info['status']=9;
  1408. }
  1409. }
  1410. }else{
  1411. if($info['status']==0){
  1412. $info['status']=3;
  1413. }elseif($info['status']==2){
  1414. $info['status']=4;
  1415. }elseif($info['status']==4||$info['status']==5){
  1416. $info['status']=8;
  1417. }elseif($info['status']==7){
  1418. $info['lower_price'] =$lower_price;
  1419. $info['status']=11;
  1420. }
  1421. }
  1422. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1423. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1424. if($token==''){
  1425. return error_show(105,"参数token不能为空");
  1426. }
  1427. $user =GetUserInfo($token);
  1428. if(empty($user)||$user['code']!=0){
  1429. return error_show(1002,"用户数据不存在");
  1430. }
  1431. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1432. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1433. Db::startTrans();
  1434. try{
  1435. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1436. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1437. "creater"=>$creater];
  1438. // $info['status'] =$status;
  1439. $info['remark'] =$remark;
  1440. $info['exam_info']=json_encode($examinfo) ;
  1441. $info['updatetime'] =date("Y-m-d H:i:s");
  1442. $up =Db::name("bargain_order")->save($info);
  1443. if($up){
  1444. //修改状态,添加待办
  1445. ActionLog::logAdd($this->post['token'], [
  1446. "order_code" => $bargainNo,//咨询单详情编号
  1447. "status" =>$ra_status,//这里的status是之前的值
  1448. "action_remark" => '',//备注
  1449. "action_type" => "status"//新建create,编辑edit,更改状态status
  1450. ], "YJD", $info['status'], $info);
  1451. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
  1452. ProcessOrder::AddProcess($token,$process);
  1453. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1454. $bidstatus=$bids['status'];
  1455. $bids['status']=5;
  1456. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1457. $bids['sale_price']=$info['after_price'];
  1458. if($bids['is_gold_price']==1){
  1459. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1460. // ->find();
  1461. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1462. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1463. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1464. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1465. }
  1466. }
  1467. $bids['updatetime']=date("Y-m-d H:i:s");
  1468. $up =Db::name("consult_bids")->save($bids);
  1469. if($up==false){
  1470. Db::rollback();
  1471. return error_show(1004,"数据更新失败");
  1472. }
  1473. ActionLog::logAdd($this->post['token'], [
  1474. "order_code" => $info["bidsNo"],//咨询单详情编号
  1475. "status" => $bidstatus,//这里的status是之前的值
  1476. "action_remark" => '',//备注
  1477. "action_type" => "status"//新建create,编辑edit,更改状态status
  1478. ], "FKD", $bids['status'], $bids);
  1479. }
  1480. Db::commit();
  1481. return app_show(0,"更新成功");
  1482. }
  1483. }catch (\Exception $e){
  1484. Db::rollback();
  1485. return error_show(1004,$e->getMessage());
  1486. }
  1487. }
  1488. public function bargain_info(){
  1489. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1490. if($bargainNo===""){
  1491. return error_show(1004,"参数bargainNo不能为空");
  1492. }
  1493. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1494. if($info==false){
  1495. return error_show(1004,"未找到议价数据");
  1496. }
  1497. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1498. if($bidinfos==false){
  1499. return error_show(1004,"未找到商品数据");
  1500. }
  1501. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1502. ->find();
  1503. if($consultinfos==false){
  1504. return error_show(1004,"未找到咨询商品数据");
  1505. }
  1506. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1507. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1508. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1509. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1510. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1511. $info['before_rate'] =round($info['before_rate']*100,2);
  1512. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1513. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1514. $info['after_rate'] = round($info['after_rate']*100,2);
  1515. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1516. if($bidinfos['brand_id']!=0){
  1517. $info['brand_id'] = $bidinfos['brand_id'];
  1518. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1519. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1520. }else{
  1521. $info["brand_name"]="";
  1522. $info["brand_id"]="";
  1523. }
  1524. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1525. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1526. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1527. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1528. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1529. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1530. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1531. $info['budget'] =$budget;
  1532. $god=[
  1533. "metal_id"=>$bidinfos['metal_id'],
  1534. "weight"=>$bidinfos["good_weight"],
  1535. "demo_fee"=>$bidinfos["demo_fee"],
  1536. "delivery_fee"=>$bidinfos["delivery_fee"],
  1537. "open_fee"=>$bidinfos["open_fee"],
  1538. "packing_fee"=>$bidinfos["pakge_fee"],
  1539. "mark_fee"=>$bidinfos["mark_fee"],
  1540. "nake_fee"=>$bidinfos["nake_fee"],
  1541. "cert_fee"=>$bidinfos["cert_fee"],
  1542. "cost_fee"=>$bidinfos["cost_fee"],
  1543. "num"=>$bidinfoe["num"],
  1544. ];
  1545. $info['gold_price']=0;
  1546. $info['noble_weight']=$bidinfos['good_weight'];
  1547. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1548. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1549. ->find();
  1550. $info['gold_price'] =$gold['price'];
  1551. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1552. }else{
  1553. if($bidinfos['nake_fee']!=0){
  1554. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1555. }else{
  1556. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1557. }
  1558. }
  1559. $info['cost_desc'] =$bidinfos['cost_desc'];
  1560. $info['work_day'] =$bidinfos['work_day'];
  1561. $info['delivery_day'] =$bidinfos['delivery_day'];
  1562. $info['expire_day'] =$bidinfos['expire_day'];
  1563. $info['origin_place'] =$bidinfos['origin_place'];
  1564. $info['origin_addr'] ="";
  1565. if($bidinfos['origin_place']!=''){
  1566. $code = explode(",",$bidinfos['origin_place']);
  1567. $temp=[];
  1568. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1569. $temp['city_code']=isset($code[1])?$code[1]:"";
  1570. $temp['area_code']=isset($code[2])?$code[2]:"";
  1571. $addr= GetAddr(json_encode($temp));
  1572. $info['origin_addr'] = $addr;
  1573. }
  1574. $info['supplierNo'] =$bidinfos['supplierNo'];
  1575. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1576. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1577. $info['pay_way'] =$bidinfos['pay_way'];
  1578. $info['tax'] =$bidinfos['tax'];
  1579. $info['send_way'] =$bidinfos['send_way'];
  1580. $info['metal_id'] =$bidinfos['metal_id'];
  1581. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1582. $info['config'] =$bidinfos['config'];
  1583. $info['other_config'] =$bidinfos['other_config'];
  1584. $info['weight'] =$bidinfos['weight'];
  1585. $info['good_weight'] =$bidinfos['good_weight'];
  1586. $info['is_diff'] =$bidinfos['is_diff'];
  1587. $info['demo_fee'] =$bidinfos['demo_fee'];
  1588. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1589. $info['open_fee'] =$bidinfos['open_fee'];
  1590. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1591. $info['nake_fee'] =$bidinfos['nake_fee'];
  1592. $info['mark_fee'] =$bidinfos['mark_fee'];
  1593. $info['cert_fee'] =$bidinfos['cert_fee'];
  1594. $info['cost_fee'] =$bidinfos['cost_fee'];
  1595. $info['total_fee'] =$bidinfos['total_fee'];
  1596. $info['supply_area'] =$bidinfos['supply_area'];
  1597. $info['remark'] =$bidinfos['remark'];
  1598. $info['is_addrs'] =$consultinfos['is_addrs'];
  1599. $info['is_custom'] =$consultinfos['is_custom'];
  1600. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1601. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1602. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1603. if($info['status']==7){
  1604. $info['lower_price'] =round($lower_price,2);
  1605. }
  1606. //获取议价原因
  1607. if ($info['result_info_id'] != 0) {
  1608. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1609. } else {
  1610. $info['result_info'] = '';
  1611. }
  1612. return app_show(0,"获取成功",$info);
  1613. }
  1614. public function bidlist(){
  1615. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1616. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1617. $where=[['is_del',"=",0]];
  1618. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1619. if ($zxNo !== "") {
  1620. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1621. }
  1622. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1623. if ($infoNo !== "") {
  1624. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1625. }
  1626. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1627. if ($bidNo !== "") {
  1628. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1629. }
  1630. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1631. if ($pgNo !== "") {
  1632. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1633. $where[] = ['infoNo','in',$bidinfo];
  1634. }
  1635. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1636. if ($bargain_status !== "") {
  1637. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1638. $where[] = ['infoNo','in',$bidinfo];
  1639. }
  1640. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1641. if ($projectNo !== "") {
  1642. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1643. ("zxNo");
  1644. $where[] = ['zxNo','in',$zxlist];
  1645. }
  1646. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1647. if($is_own==1){
  1648. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1649. if($token==""){
  1650. return error_show(101,'token不能为空');
  1651. }
  1652. $apply_id =GetUserInfo($token);
  1653. if(empty($apply_id)||$apply_id['code']!=0){
  1654. return error_show(1002,"申请人数据不存在");
  1655. }
  1656. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1657. $where[]=['createrid',"=",$rm];
  1658. }
  1659. $count = Db::name('consult_bids')->where($where)->count();
  1660. $total = ceil($count / $size);
  1661. $page = $page >= $total ? $total : $page;
  1662. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1663. $data=[];
  1664. foreach ($list as $value){
  1665. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1666. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1667. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1668. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1669. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1670. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1671. if($value['brand_id']!=0){
  1672. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1673. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1674. }else{
  1675. $value["brand_name"]="";
  1676. $value["brand_id"]="";
  1677. }
  1678. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1679. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1680. $god=[
  1681. "metal_id"=>$value['metal_id'],
  1682. "weight"=>$value["good_weight"],
  1683. "demo_fee"=>$value["demo_fee"],
  1684. "delivery_fee"=>$value["delivery_fee"],
  1685. "open_fee"=>$value["open_fee"],
  1686. "packing_fee"=>$value["pakge_fee"],
  1687. "mark_fee"=>$value["mark_fee"],
  1688. "nake_fee"=>$value["nake_fee"],
  1689. "cert_fee"=>$value["cert_fee"],
  1690. // "cost_fee"=>$value["cost_fee"],
  1691. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1692. //暂时注掉,搞不清楚原因@吴广广
  1693. "num"=>$bidinfo["num"],
  1694. ];
  1695. $top_cat = made($value['cat_id']);
  1696. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1697. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1698. $price = GoldPrice($god, $budget/100);
  1699. $value['sale_price'] = round($price,2);
  1700. }
  1701. $value['cost_fee'] =$value['origin_cost_fee'];
  1702. $value['specinfo'] = json_decode($value['specinfo'],true);
  1703. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1704. $value['bargain_status']=$bidinfo['bargain_status'];
  1705. //reject驳回原因,status==5表示驳回
  1706. $value['reject']=[];
  1707. if ($value['status'] >=5) {
  1708. $value['reject'] = Db::name('bargain_order')
  1709. ->field('id,remark,status')
  1710. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1711. ->whereIn('status', [3,8,11])->order("id desc")
  1712. ->find();
  1713. }
  1714. //产地
  1715. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1716. if($value['delivery_place']!=""){
  1717. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1718. }
  1719. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1720. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1721. if($value['origin_place']!=""){
  1722. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1723. }
  1724. $value['origin_addr']=GetAddr(json_encode($place));
  1725. // if($value['origin_place']!=''){
  1726. // $code = explode(",",$value['origin_place']);
  1727. // $temp=[];
  1728. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1729. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1730. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1731. // $addr= GetAddr(json_encode($temp));
  1732. // $value['origin_addr'] = $addr;
  1733. // }
  1734. $data[] = $value;
  1735. }
  1736. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1737. }
  1738. public function feedlist(){
  1739. $where=[['is_del',"=",0]];
  1740. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1741. if ($zxNo !== "") {
  1742. $where[] = ['zxNo','=',$zxNo];
  1743. }
  1744. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1745. if ($infoNo !== "") {
  1746. $where[] = ['infoNo','=',$infoNo];
  1747. }
  1748. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1749. if ($bidNo !== "") {
  1750. $where[] = ['bidNo','=',$bidNo];
  1751. }
  1752. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1753. if ($projectNo !== "") {
  1754. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1755. ("zxNo");
  1756. $where[] = ['zxNo','in',$zxlist];
  1757. }
  1758. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1759. if($token==''){
  1760. return error_show(102,"参数token不能为空");
  1761. }
  1762. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1763. if($is_own==1){
  1764. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1765. if($token==""){
  1766. return error_show(101,'token不能为空');
  1767. }
  1768. $apply_id =GetUserInfo($token);
  1769. if(empty($apply_id)||$apply_id['code']!=0){
  1770. return error_show(1002,"申请人数据不存在");
  1771. }
  1772. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1773. $where[]=['createrid',"=",$rm];
  1774. }
  1775. $list =Db::name('consult_bids')->where($where)->select();
  1776. $data=[];
  1777. foreach ($list as $value){
  1778. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1779. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1780. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1781. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1782. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1783. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1784. if($value['brand_id']!=0){
  1785. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1786. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1787. }else{
  1788. $value["brand_name"]="";
  1789. $value["brand_id"]="";
  1790. }
  1791. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1792. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1793. $god=[
  1794. "metal_id"=>$value['metal_id'],
  1795. "weight"=>$value["good_weight"],
  1796. "demo_fee"=>$value["demo_fee"],
  1797. "delivery_fee"=>$value["delivery_fee"],
  1798. "open_fee"=>$value["open_fee"],
  1799. "packing_fee"=>$value["pakge_fee"],
  1800. "mark_fee"=>$value["mark_fee"],
  1801. "nake_fee"=>$value["nake_fee"],
  1802. "cert_fee"=>$value["cert_fee"],
  1803. "cost_fee"=>$value["cost_fee"],
  1804. "num"=>$bidinfo["num"],
  1805. ];
  1806. if ($value['is_gold_price'] == 1 ) {
  1807. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1808. ->find();
  1809. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1810. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1811. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1812. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1813. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1814. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1815. }else{
  1816. if($value["nake_fee"]){
  1817. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1818. }else{
  1819. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1820. (1 - $budget);
  1821. }
  1822. }
  1823. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1824. $value['specinfo'] = json_decode($value['specinfo'],true);
  1825. $value['bargain_status']=$bidinfo['bargain_status'];
  1826. $data[]=$value;
  1827. }
  1828. return app_show(0,"获取成功",$data);
  1829. }
  1830. public function bragain_list(){
  1831. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1832. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1833. $where=[['bo.is_del',"=",0]];
  1834. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1835. if($bidsNo!=""){
  1836. $where[]=["bo.bidsNo","=",$bidsNo];
  1837. }
  1838. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1839. if ($zxNo !== "") {
  1840. $where[] = ['bo.zxNo','=',$zxNo];
  1841. }
  1842. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1843. if ($bargainNo !== "") {
  1844. $where[] = ['bo.bargainNo','=',$bargainNo];
  1845. }
  1846. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1847. if ($status!== "") {
  1848. $where[] = ['bo.status','=',$status];
  1849. }
  1850. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1851. if ($infoNo !== "") {
  1852. $where[] = ['bo.infoNo','=',$infoNo];
  1853. }
  1854. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1855. if ($projectNo !== "") {
  1856. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1857. ("zxNo");
  1858. $where[] = ['bo.zxNo','in',$zxlist];
  1859. }
  1860. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1861. if ($pgNo !== "") {
  1862. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1863. $where[] = ['bo.infoNo','in',$bidinfo];
  1864. }
  1865. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1866. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1867. if($start!=""){
  1868. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1869. }
  1870. if($end!=""){
  1871. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1872. }
  1873. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1874. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1875. $role=$this->checkRole();
  1876. if(!empty($role['write'])){
  1877. $where[]=["bo.createrid","in",$role['write']];
  1878. }
  1879. $count=Db::name("bargain_order")->alias('bo')->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")->where($where)->count();
  1880. $total = ceil($count / $size);
  1881. $page = $page >= $total ? $total : $page;
  1882. $list = Db::name('bargain_order')
  1883. ->alias('bo')
  1884. ->field('bo.*,u.itemid')
  1885. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1886. ->where($where)
  1887. ->page($page, $size)
  1888. ->order('bo.addtime', 'desc')
  1889. ->cursor();
  1890. $data=[];
  1891. foreach ($list as $value){
  1892. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1893. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1894. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1895. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1896. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1897. if($bidinfos['brand_id']!=0){
  1898. $value['brand_id'] = $bidinfos['brand_id'];
  1899. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1900. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1901. }else{
  1902. $value["brand_name"]="";
  1903. $value["brand_id"]="";
  1904. }
  1905. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1906. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1907. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1908. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1909. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1910. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1911. $value['budget'] =$budget;
  1912. $god=[
  1913. "metal_id"=>$bidinfos['metal_id'],
  1914. "weight"=>$bidinfos["good_weight"],
  1915. "demo_fee"=>$bidinfos["demo_fee"],
  1916. "delivery_fee"=>$bidinfos["delivery_fee"],
  1917. "open_fee"=>$bidinfos["open_fee"],
  1918. "packing_fee"=>$bidinfos["pakge_fee"],
  1919. "mark_fee"=>$bidinfos["mark_fee"],
  1920. "nake_fee"=>$bidinfos["nake_fee"],
  1921. "cert_fee"=>$bidinfos["cert_fee"],
  1922. "cost_fee"=>$bidinfos["cost_fee"],
  1923. "num"=>$bidinfoe["num"],
  1924. ];
  1925. // if($bidinfos['is_gold_price']==1){
  1926. // $price = GoldPrice($god, $budget/100);
  1927. // }else{
  1928. // $price = GoodPrice($god, $budget/100);
  1929. // }
  1930. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1931. $value['sale_price'] =round($bidinfos['origin_price'],2);
  1932. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1933. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1934. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  1935. $data[]=$value;
  1936. }
  1937. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1938. }
  1939. public function crontablist(){
  1940. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1941. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1942. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1943. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1944. if ($zxNo !== "") {
  1945. $where[] = ['a.zxNo','=',$zxNo];
  1946. }
  1947. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1948. if ($salesman !== "") {
  1949. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1950. $where[]= ["b.salesman",'like',"%$salesman%"];
  1951. }
  1952. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1953. if ($cpName !== "") {
  1954. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1955. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1956. }
  1957. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1958. if ($khNo !== "") {
  1959. // $where['khNo'] = $khNo;
  1960. $where[]= ["b.khNo",'like',"%$khNo%"];
  1961. }
  1962. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1963. if ($start !="") {
  1964. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1965. $where[]= ["a.addtime",'>=',$start];
  1966. }
  1967. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1968. if($end !=""){
  1969. $where[]= ["a.addtime",'<=',$end];
  1970. }
  1971. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1972. if ($status !== "") {
  1973. $where[]= ["a.status",'=',$status];
  1974. }
  1975. // $role=$this->checkRole();
  1976. // if(!empty($role['platform']) ){
  1977. // $where[]=["b.platform_code","in",$role['platform']];
  1978. // }
  1979. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1980. ->count();
  1981. $total = ceil($count / $size);
  1982. $page = $page >= $total ? $total : $page;
  1983. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1984. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  1985. $data=[];
  1986. foreach ($list as $value){
  1987. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1988. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1989. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1990. $value['khname']="";
  1991. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1992. true):[];
  1993. if($value['khNo']!==""){
  1994. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1995. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1996. }
  1997. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  1998. ->find();
  1999. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2000. $value['is_feed'] =$consult==false?0:1;
  2001. $value['is_all_feed'] =$consults==false?0:1;
  2002. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2003. $data[]=$value;
  2004. }
  2005. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2006. }
  2007. //复制上面的bidlist方法,只更改排序方式
  2008. public function bidlistCopy()
  2009. {
  2010. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2011. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2012. $where = [['cb.is_del', "=", 0]];
  2013. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2014. if ($zxNo !== "") {
  2015. $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2016. }
  2017. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2018. if ($infoNo !== "") {
  2019. $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2020. }
  2021. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2022. if ($bidNo !== "") {
  2023. $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2024. }
  2025. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2026. if ($pgNo !== "") {
  2027. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2028. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2029. }
  2030. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2031. if ($bargain_status !== "") {
  2032. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2033. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2034. }
  2035. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2036. if ($projectNo !== "") {
  2037. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column
  2038. ("zxNo");
  2039. $where[] = ['cb.zxNo', 'in', $zxlist];
  2040. }
  2041. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2042. if ($is_own == 1) {
  2043. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2044. if ($token == "") {
  2045. return error_show(101, 'token不能为空');
  2046. }
  2047. $apply_id = GetUserInfo($token);
  2048. if (empty($apply_id) || $apply_id['code'] != 0) {
  2049. return error_show(1002, "申请人数据不存在");
  2050. }
  2051. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2052. $where[] = ['cb.createrid', "=", $rm];
  2053. }
  2054. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2055. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2056. $count = Db::name('consult_bids')->alias('cb')->where($where)->count();
  2057. $total = ceil($count / $size);
  2058. $page = $page >= $total ? $total : $page;
  2059. $list = Db::name('consult_bids')
  2060. ->alias('cb')
  2061. ->field('cb.*,u.itemid')
  2062. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2063. ->where($where)
  2064. ->page($page, $size)
  2065. ->order('cb.addtime', 'desc')
  2066. ->cursor();
  2067. $data = [];
  2068. foreach ($list as $value) {
  2069. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2070. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2071. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2072. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2073. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2074. $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2075. if ($value['brand_id'] != 0) {
  2076. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2077. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2078. } else {
  2079. $value["brand_name"] = "";
  2080. $value["brand_id"] = "";
  2081. }
  2082. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2083. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2084. $god = [
  2085. "metal_id" => $value['metal_id'],
  2086. "weight" => $value["good_weight"],
  2087. "demo_fee" => $value["demo_fee"],
  2088. "delivery_fee" => $value["delivery_fee"],
  2089. "open_fee" => $value["open_fee"],
  2090. "packing_fee" => $value["pakge_fee"],
  2091. "mark_fee" => $value["mark_fee"],
  2092. "nake_fee" => $value["nake_fee"],
  2093. "cert_fee" => $value["cert_fee"],
  2094. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2095. "num" => $bidinfo["num"],
  2096. ];
  2097. if ($value['is_gold_price'] == 1) {
  2098. $price = GoldPrice($god, $budget / 100);
  2099. $value['sale_price'] = round($price, 2);
  2100. }
  2101. $value['cost_fee'] = $value['origin_cost_fee'];
  2102. $value['specinfo'] = json_decode($value['specinfo'], true);
  2103. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2104. $value['bargain_status'] = $bidinfo['bargain_status'];
  2105. //reject驳回原因,status==5表示驳回
  2106. $value['reject'] = [];
  2107. if ($value['status'] >= 5) {
  2108. $value['reject'] = Db::name('bargain_order')
  2109. ->field('id,remark,status')
  2110. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2111. ->whereIn('status', [3, 8, 11])->order("id desc")
  2112. ->find();
  2113. }
  2114. //产地
  2115. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2116. if ($value['delivery_place'] != "") {
  2117. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2118. }
  2119. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2120. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2121. if ($value['origin_place'] != "") {
  2122. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2123. }
  2124. $value['origin_addr'] = GetAddr(json_encode($place));
  2125. // if($value['origin_place']!=''){
  2126. // $code = explode(",",$value['origin_place']);
  2127. // $temp=[];
  2128. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2129. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2130. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2131. // $addr= GetAddr(json_encode($temp));
  2132. // $value['origin_addr'] = $addr;
  2133. // }
  2134. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2135. $data[] = $value;
  2136. }
  2137. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2138. }
  2139. }